﻿module GameState

    open System
    open Microsoft.FSharp.Core.LanguagePrimitives
    open Microsoft.Xna.Framework
    open Microsoft.Xna.Framework.Input
    open Utilities
    open Casanova
    open Coroutines
        
    open InputManagement   


    let screenWidth = 1366.0f
    let screenHeight = 768.0f

    
    let mutable isShooting = false
    let mutable isSuperShot = false
        
    type Event = { i : int; s : string}
    
    type GameState = 
        {
            Player              : GameEntity
            Enemies             : Variable<List<Enemy>>
            mutable Timer       :int
            mutable Score       :int
            mutable Level       :string
            mutable GameOver    :bool
            mutable BestTime    :int
        }

     and GameEntity =
        {
            Position            :Variable<Vector2>
            Velocity            :Variable<Vector2>
            Speed               :float32
            DirectionFire       :Variable<float32>
            Projectiles         :Variable<List<Projectile>>
            mutable BBox        :BoundingBox
            mutable Event       :Option<Event>
            mutable Alive       :bool
        }
   
    and Enemy =
        {
            Position            :Variable<Vector2>
            Velocity            :Variable<Vector2>
            Speed               :float32
            Mass                :float32
            IsActive            :Variable<bool>
            Type                :int
            mutable Heading     :float32
            mutable BBox        :BoundingBox
        }

    and Projectile = 
        {
            Position            :Variable<Vector2>
            Velocity            :Vector2
            Rotation            :float32
            CollidersA          :Variable<List<Enemy>>
            isActive            :Variable<bool>
            BBox                :BoundingBox
            Type                :int
            mutable Event       :Option<Event>
        }
        
    let rec setState (level : string) : GameState  =
        {
            Player = 
                {
                    Position        = variable(Vector2(screenWidth / 2.0f - 15.0f, screenHeight / 2.0f + 65.5f))
                     
                    Velocity        = variable(Vector2.Zero)                   
                    Speed           = 150.0f
                    DirectionFire   = variable(-MathHelper.PiOver2)
                    Projectiles     = Variable(fun() -> [])
                    BBox            = 
                                    BoundingBox(new Vector3(screenWidth/2.0f - 15.0f,screenHeight / 2.0f + 65.5f,0.0f), new Vector3(screenWidth/2.0f + 15.0f,screenHeight /2.0f + 55.0f,0.0f))
                    Event           = None
                    Alive           = true
                }
           
            Enemies = Variable(fun() -> [])

            Score = 0
    
            Timer = -15

            Level = level

            GameOver = false

            BestTime = 0
        }

    